package com.dwy2002.order;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dwy2002.common.Result;
import com.dwy2002.common.annotation.RequiresPermission;
import com.dwy2002.enums.Logical;
import com.dwy2002.order.service.IOrdersService;
import com.dwy2002.pojo.dto.order.OrderDTO;
import com.dwy2002.pojo.dto.order.OrderUpdateDTO;
import com.dwy2002.pojo.dto.order.OrdersPageDTO;
import com.dwy2002.pojo.po.order.Orders;
import com.dwy2002.pojo.vo.order.OrderVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 杜伟毅
 * @version 1.0
 * @since 2025/03/08
 */
@RestController
@RequestMapping("/orders")
@RequiredArgsConstructor
public class OrdersController {
    private final IOrdersService service;

    /**
     * 生成订单
     *
     * @param dto 前端传的订单信息
     * @author 杜伟毅
     * @since 2025/3/8 0008 15:52
     */
    @PostMapping
    public Result<Void> generateOrder(@RequestBody OrderDTO dto) {
        return service.generateOrder(dto);
    }

    /**
     * 删除订单
     *
     * @param ids 订单id集合
     * @author 杜伟毅
     * @since 2025/3/8 0008 22:33
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @DeleteMapping
    public Result<Void> deleteOrder(@RequestBody List<String> ids) {
        return service.deleteOrder(ids);
    }

    /**
     * 有限制的修改订单
     *
     * @param dto 修改订单DTO
     * @author 杜伟毅
     * @since 2025/3/8 0008 23:12
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @PutMapping
    public Result<Void> updateOrder(@RequestBody OrderUpdateDTO dto) {
        return service.updateOrder(dto);
    }

    /**
     * 订单分页查询
     *
     * @param dto 订单分页数据DTO
     * @author 杜伟毅
     * @since 2025/3/9 0009 15:11
     */
    @PostMapping("/page")
    public Result<Page<Orders>> getOrdersPage(@RequestBody OrdersPageDTO dto) {
        return service.getOrdersPage(dto);
    }

    /**
     * 获取订单详情
     *
     * @param id 订单id
     * @author 杜伟毅
     * @since 2025/3/12 0012 21:53
     */
    @GetMapping("/{id}")
    public Result<OrderVO> getOrderDetails(@PathVariable String id) {
        return service.getOrderDetails(id);
    }

    /**
     * 完成订单
     *
     * @param id 订单id
     * @author 杜伟毅
     * @since 2025/3/16 0016 0:20
     */
    @PutMapping("/{id}")
    public Result<Void> accomplishOrder(@PathVariable String id) {
        return service.accomplishOrder(id);
    }
}
